***** Page Count *****

global folder "~\Dropbox\cartelle condivise\Ash_Morelli_Vannoni\_papers\2-complexity-growth\replication_23_5_24"

cd "$folder/data"   

import delimited using "$folder/data/input/page_count.csv", clear

keep if  state == "ME" |state == "NB" | state == "MA" | state == "NH" | state == "PR" | state == "RI" | state == "CT" | state == "NY" | state == "VT" | state == "DE" | state == "NJ" | state == "PA" | state == "MD" | state == "NC" | state == "SC" | state == "VA" | state == "WV" | state == "LA" | state == "MS" | state == "TX" |state == "KY" | state == "MI" | state == "OH" | state == "TN" | state == "IL" | state == "IN" | state == "WI" | state == "AR" | state == "IA" | state == "MN" | state == "MO" | state == "NE" | state == "ND" | state == "SD"| state == "AK" | state == "AZ" | state == "CA" | state == "HI" | state == "ID" | state == "MT" | state == "NV" | state == "OR" | state == "WA" | state == "CO" | state == "KS" | state == "NM" | state == "OK" | state == "UT" | state == "WY" | state == "AL" | state == "FL" | state == "GA"

collapse (sum) page_count , by(state year)

destring year, replace
gen biennium =  year + mod(year,2)
rename biennium year1

drop year

rename year1 year

collapse (sum) page_count, by(state year)

rename state state_abbrev

save dataset_pagecount, replace



***** Government Data *****
import excel using "$folder/data/input/Partisan_Balance_For_Use2011_06_09b.xlsx", first clear

gen biennium =  year + mod(year,2)
rename biennium year1
drop year
rename year1 year
rename state statename
collapse (last) government_cont, by(statename year)

gen demm=government_cont*3
gen dem_control=round(demm)

save gov_controls, replace

***** Federal Regulation Influence *****
import delimited "$folder/data/input/frase_index_2017.csv", clear
rename state statename
save frase_index_2017, replace

import delimited "$folder/data/input/quantgov_extract_total_restrictions_united_states.csv", clear
rename period year
save total_quantgov, replace

***** Uncertainty News *****

import delimited "$folder/data/input/state_uncertainty", clear

drop state
rename abbrev state_abbrev
gen state_unc = nyt_state + wp_state + wsj_state
gen economic_unc = nyt_economic + wp_economic + wsj_economic
gen total_unc = nyt_total + wp_total + wsj_total
gen ratio_unc = state_unc / economic_unc
gen ratio_tot = state_unc / total_unc

* biennium includes stated year and previous year

destring year, replace
gen biennium =  year + mod(year,2)
rename biennium year1
drop year
rename year1 year
collapse (mean) state_unc economic_unc total_unc ratio_unc ratio_tot, by(state_abbrev year)
save dataset_fed_news, replace

***articles in state papers
*articles containing economic uncertainty

clear
import delimited "$folder/data/input/econom%2a+uncertain%2a"

statastates, name(state)

rename yr year
gen biennium =  year + mod(year,2)
rename biennium year1
drop year
rename year1 year
drop if missing(state_abbrev) 
replace obs = subinstr(obs, ",", "",.) 

destring obs, generate(econ_uncert)
collapse (mean) econ_uncert, by(state_abbrev year)

save dataset_econ_uncert, replace

* tot articles
clear
import delimited "$folder/data/input/from"

statastates, name(state)

rename yr year
gen biennium =  year + mod(year,2)
rename biennium year1
drop year
rename year1 year
drop if missing(state_abbrev) 
replace obs = subinstr(obs, ",", "",.) 

destring obs, generate(all_news)
collapse (mean) all_news, by(state_abbrev year)

save dataset_all_news, replace

**

merge 1:1 state_abbrev year using dataset_econ_uncert
keep if _merge == 3

gen state_news_uncertain = econ_uncert / all_news

save dataset_state_news_uncertain, replace

******* Uncertainty Economic
describe using "$folder/data/input/gss-with-state.dta"
use state year fipsstat formwt wtssall state wtssnr wtss joblose jobfind satfin finalter occ using "$folder/data/input/gss-with-state.dta", clear

recode joblose (5 8 9 0 = .) (1 2 3 = 1 "high")  (4 = 0 "low"), gen(joblose_new) 
recode jobfind (8 9 0 = .) (1 2 = 0 "low") (3 = 1 "high"), gen(jobfind_new) 
recode satfin (8 9 0 = .) (1 = 0 "low") (2 3 = 1 "high"), gen(satfin_new) 
recode finalter (8 9 0 = .) (1 = 0 "low") (2 3 = 1 "high"), gen(finalter_new) 

recode joblose (5 8 9 0 = .) (1 = 3 "very high") (2 = 2 "high") (3 = 1 "low") (4 = 0 "very low"), gen(joblose_new0) 
recode jobfind (8 9 0 = .) (3 = 2 "high") (2 = 1 "mid") (1 = 0 "low"), gen(jobfind_new0) 
recode satfin (8 9 0 = .) (3 = 2 "high") (2 = 1 "mid") (1 = 0 "low"), gen(satfin_new0) 
recode finalter (8 9 0 = .) (3 = 1 "mid") (2 = 2 "high") (1 = 0 "low"), gen(finalter_new0) 


collapse (mean)   joblose_new jobfind_new satfin_new finalter_new  joblose_new0 jobfind_new0 satfin_new0 finalter_new0 [aweight=formwt], by(state year)

statastates, fips(state)

* biennium includes stated year and previous year

destring year, replace
gen biennium =  year + mod(year,2)
rename biennium year1

drop year

rename year1 year

collapse (mean) joblose_new jobfind_new satfin_new finalter_new  joblose_new0 jobfind_new0 satfin_new0 finalter_new0  , by(state_abbrev year)


save dataset_unc, replace

****State Regulation

clear all
set more off

import delimited using "$folder/data/input/state_reg.csv", clear

rename state state_abbrev

gen biennium =  year + mod(year,2)
replace year = biennium

collapse (sum) record_count word_count word_count_avg_per_opinion word_count_min word_count_max, by(state_abbrev year)

rename word_count word_count_reg

foreach x in  word_count_reg  {

gen log_`x' = log(`x')

}

save data_statereg, replace


****Court Cases

clear all

import delimited using "$folder/data/input/lexis_cases_state.csv", clear

rename state state_abbrev

gen biennium =  year + mod(year,2)
replace year = biennium

collapse (sum)  case_count opinion_count word_count word_count_avg_per_opinion word_count_min word_count_max, by(state_abbrev year)

keep if year>1964
keep if year<2018

rename word_count word_count_courts

*gen log_fed_reg = log(fed_reg)

foreach x in case_count opinion_count word_count_courts word_count_avg_per_opinion  {

gen log_`x' = log(`x')

}

save data_court, replace


*Campaign Contributions

clear all
set more off

import delimited using "$folder/data/input/state_biennium_donations.csv", clear

rename state state_abbrev
rename biennium year
drop v1

save campaign, replace

****Lobbying regulation

clear all
set more off

import delimited using "$folder/data/input/campaign-finance-legislation.csv", clear

gen year1=year+1

drop year

rename year1 year

rename state state_abbrev

gen contri_dum = 1
replace contri_dum = 0 if contributionslimit==1
replace contri_dum = 0 if contributionslimit==2

gen contri = 2
replace contri = 1 if contributionslimit==1
replace contri = 0 if contributionslimit==2

save lobbying, replace

